// es5写法
// export const JingpingAPI = function () {
//   return request.get("/products/recommend");
// };

// 统一管理项目中所有的请求路径 api
import request from "./request";
import qs from "qs"; // 引入qs插件

// 首页精品推荐请求
export const JingpingAPI = () => request.get("/products/recommend");

// 首页热门兑换请求
export const RemenAPI = () => request.get("/products/hot");

// 发送短信验证码请求
export const SendSMSAPI = (params) =>
  request.post("/sendSMS", qs.stringify(params));

// 手机号验证码登录请求
export const PhoneLoginAPI = (params) =>
  request.post("/phoneRegin", qs.stringify(params));

// 微信登录(这个接⼝必须⽤qs对数据进⾏格式化)
export const WeixinLoginApI = (params) =>
  request.post("/wechatUsers/PCLogin", qs.stringify(params));

// 手机绑定微信
export const BindPhoneApI = (params) =>
  request.post("/wechatUsers/binding", qs.stringify(params));

// 获取用户信息
export const UserProfilesAPI = () => request.get("/shop/userProfiles");

// 商品详情请求
export const GoodsDetailsAPI = (id) => request.get(`/products/${id}`);

// 加入到购物车请求
export const AddToCartAPI = (params) =>
  request.post("/shop/carts/add", qs.stringify(params));

// 商品搜索（含首页的“更多”）
export const GoodsSearchAPI = (params) => request.get("/products", { params });

// 查看购物车
export const CartDataApi = (params) => request.get("/shop/carts", { params });

// 购物车删除商品
export const delCartDataAPI = (params) =>
  request.delete(`/shop/carts?productIds=${params.id}`);

// 在组件中使用
// SendSMSAPI({
//   phone: this.phoneNum,
// });

// console.log(JSON.stringify({ aa: 10, bb: 20 })); // {"aa":10,"bb":20}
// console.log(qs.stringify({ aa: 10, bb: 20 })); // aa=10&bb=20
